﻿using System.Text;
using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using 请求响应加密.DAL;
using 请求响应加密.Models.SqlSugarDemo;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace 请求响应加密.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class WorkflowEngineController : ControllerBase
    {
        private IRepository repository;

        public WorkflowEngineController(IRepository repository)
        {
            this.repository = repository;
        }

        [HttpGet]
        [Route("CodeGenerate")]
        public IActionResult CodeGenerate()
        {
            return Ok("实体类生成完成");
        }

        [HttpGet]
        [Route("classInfo")]
        public IActionResult ClassInfo()
        {
            string modelPath = "D:\\Code\\WebAPI\\请求响应加密\\Models\\SugarPMS";
            string[] files = Directory.GetFiles(modelPath);
            foreach (string file in files)
            {
                Console.WriteLine($"handle file {file} Tenant......");
                string modelName = file.Substring(file.Replace(".cs", "").LastIndexOf(Path.DirectorySeparatorChar) + 1).Replace(".cs", "");
                string content = System.IO.File.ReadAllText(file, Encoding.UTF8);
                string matchStr = $"public partial class {modelName}";
                Match match = Regex.Match(content, matchStr);
                int idx = match.Index;
                content = content.Insert(idx, "[Tenant(\"SugarPMS\")]\n    ");
                Console.WriteLine(content);
            }
            return Ok();
        }
    }
}
